package cn.biplam.front.template.buttons;

import cn.biplam.common.paramters.SysCaption;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.data.common.ButtonComp;
import cn.biplam.front.html.HtmlValue;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Window_Event;
import cn.biplam.front.htmlscript.script.AjxScript;
import cn.biplam.front.htmlscript.script.AjxScript.Is_SubMitData;
import cn.biplam.front.template.base.Button;

/**
 *  修改按钮模板
 * @author XiaoRuxing Dec 3, 200910:07:20 AM
 * @version 1.0
 */
public class EditButton {

	private UserInfo mUser;
	private String cID;
	private String aID;
	private String rID;
	private String caption;
	private Is_SubMitData isSubmitData = Is_SubMitData.NoSubmit;
	
	/**
	 * 构造方法
	 * @param mUser		用户信息类
	 * @param cID		按钮提交时,需要提交数据的容器ID
	 * @param aID		按钮的actionID
	 */
	public EditButton(UserInfo mUser,String cID,String aID){
		this(mUser, cID, aID, null);
	}

	/**
	 * 传入rid时,cID是按钮的ID,不是提交容器ID
	 * @param mUser		用户信息类
	 * @param cID		按钮的ID
	 * @param aID		按钮的actionID
	 * @param rID		提交的recordId
	 */
	public EditButton(UserInfo mUser,String cID,String aID,String rID){
		this.mUser=mUser;
		this.cID=cID;
		this.aID=aID;
		this.rID=rID;
	}
	
	/**
	 *  是否提交参数
	 * @param isSubmitData
	 */
	public void isSubmitData(boolean isSubmitData){
		if(isSubmitData){
			this.isSubmitData = Is_SubMitData.Submit;
		}
	}
	
	/**
	 *  设置编辑按钮标题
	 * @param caption
	 */
	public void setCaption(String caption){
		this.caption=caption;
	}

	public HtmlWindow get() throws ErrorMessage {
		HtmlWindow addBt;
		if(this.caption==null){
			addBt=ButtonComp.get(mUser, SysCaption.Edit);
		}else{
			addBt=new Button(this.caption).get();
		}
		
		//如果传入rID,则使用传入ID作为按钮ID,并以按钮为提交数据容器,创建隐藏rid
		if(this.rID!=null){
			addBt.setID(this.cID);
			addBt.put(new HtmlValue(cID+"r",rID));
		}//否则假定传入容器中包含有隐藏rid

		addBt.bind(Window_Event.OnClick,AjxScript.getPr(cID,aID,this.isSubmitData,null));
		return addBt;
	}
}
